#if !MVCUI_CUSTOM_ENABLED
using UnityEditor;
using UnityEngine;
namespace Life.UI.MVC.Editor
{
    [CustomPropertyDrawer(typeof(ControllerTypeSelectAttribute))]
    public class ControllerTypePropertyDrawer : PropertyDrawer
    {
        private string[] names = null;
        private int[] values = null;
        private int index = -1;
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (Application.isPlaying)
            {
                EditorGUI.BeginDisabledGroup(true); 
                EditorGUI.PropertyField(position, property, label);
                EditorGUI.EndDisabledGroup(); 
            }
            else
            {
                if (values == null)
                {
                    SelectedMsg();
                }
                var selected = property.intValue;
                if (index == -1)
                {
                    index = 0;
                    for (int i = 0; i < values.Length; i++)
                    {
                        if (values[i] == selected)
                        {
                            index = i;
                            break;
                        }
                    }
                }
                index = EditorGUI.Popup(position, property.displayName, index, names);
                property.intValue = values[index];
            }
        }

        void SelectedMsg()
        {
            int length = ControllerType.Length;
            names = new string[length];
            values = new int[length];
            for (int i = 0; i < length; i++)
            {
                names[i] = ControllerType.GetName(i);
                values[i] = ControllerType.GetValue(i);
            }
        }
    }
}
#endif